﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Jumpton.SFA.Server.BusinessRule.MasterData;
using Jumpton.SFA.Server.Entity;
using com.SFA.Server.Entity;
/// <summary>
/// 仓库维护
/// Update By:Allen Jiang
/// UpdateTime：2008-12-25 
/// Description：
///      修改编辑功能在本页面
/// </summary>
public partial class masterdata_Warehouse_Locations_List : PageBase
{
    WareHouseManager manager = new WareHouseManager();
    private const string RESPONSE_PROUCT_LIST = "Customer_Product_Choose.aspx";
    private const string RESOONSE_WAREHOUSE_DETAIL = "WareHouse_Detail.aspx";

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            GetWareHouseBind();
        }
    }

    /// <summary>
    /// 页面数据绑定
    /// </summary>
    public void GetWareHouseBind()
    {
        GridPager1.DataSource = WareHouseManager.GetWareHouse(MyStateManager.DomainID);
        GridPager1.GridView = GridView1;
        GridPager1.BindData();
        GridPager1.Visible = GridView1.Rows.Count > 0;
    }
    /// <summary>
    /// 新增
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnAdd_Click(object sender, EventArgs e)
    {
        DetailsView1.ChangeMode(DetailsViewMode.Insert);
        DetailsView1.DataBind();
        SetStatus();
    }
  

    /// <summary>
    /// 设置状态
    /// </summary>
    private void SetStatus()
    {
      //  editArea.Visible = true;
     //   editArea.Style.Add("width", "60%");
        //back.Attributes.Add("class", "back");
    }

    /// <summary>
    /// 数据保存方法
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnSave_Click(object sender, EventArgs e)
    {
        try
        {
            WAREHOUSE ShipFrom = null;
            WareHouseManager manager = new WareHouseManager();
            TextBox ctl = DetailsView1.FindControl("txtCode") as TextBox;

            if (DetailsView1.CurrentMode == DetailsViewMode.Insert)  //新增
            {
                ShipFrom = new WAREHOUSE();
            }
            else //编辑
            {
                ShipFrom = manager.Load(int.Parse(GridView1.SelectedDataKey.Value.ToString()));
            }

            ShipFrom.CODE = ctl.Text;

            ctl = DetailsView1.FindControl("txtName") as TextBox;
            ShipFrom.DESCRIPTION = ctl.Text;

            ctl = DetailsView1.FindControl("txtArea") as TextBox;
            ShipFrom.DEPARTUREDISTRIBUTIONAREA = ctl.Text;

            CheckBox ckbIsValid = DetailsView1.FindControl("chkValid") as CheckBox;
            ShipFrom.ACTIVE = ckbIsValid.Checked ;
            ShipFrom.LASTUPDATETIME = Jumpton.SFA.Server.BusinessRule.BusinessLogic.GetDateTimeDecimal(DateTime.Now);
            ShipFrom.LASTUPDATER = MyStateManager.Name;
            ShipFrom.DOMAINID = MyStateManager.DomainID;

            manager.Save(ShipFrom);
            GetWareHouseBind();
            ShowMessage("保存成功",this.Request.Url.ToString());
        }
        catch (Exception ex)
        {
            ShowMessage(ex.Message);
        }
    }

    /// <summary>
    /// 取消方法
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnCancel_Click(object sender, EventArgs e)
    {
        //editArea.Visible = false;
       //ack.Attributes.Remove("class");
    }

    /// <summary>
    /// 绑定
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void DetailsView1_DataBound(object sender, EventArgs e)
    {
        CheckBox chk = DetailsView1.FindControl("chkValid") as CheckBox;

        if (DetailsView1.DataItem == null)
        {
            chk.Checked = true;
        }
    }

    /// <summary>
    /// 编辑事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
    {
        DetailsView1.ChangeMode(DetailsViewMode.Edit);
        DetailsView1.DataBind();

        SetStatus();
    }

   
}
